<template>
  <div style="background: #fff">
    <div class="title">
      <div>{{ title }}</div>
    </div>
     <div style="text-align:right">
      <el-form :inline="true">
        <el-form-item>
           
          <el-button @click="reset" v-if="query.p_id>0">返回上级</el-button>
          <el-button type="primary" @click="showEdit(false)">添加</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="data"
      stripe
      style="width: 100%; margin-bottom: 1.875rem"
    
    >
      </el-table-column>
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column prop="name" label="名称"></el-table-column>
       <el-table-column label="是否显示">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.is_show"
            :active-value="2"
            :inactive-value="1"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="changeSwitch(scope.row)"
           >
         </el-switch>
         
        </template>
      </el-table-column>
       <el-table-column v-if="query.p_id>0" prop="rate"  label="费率"></el-table-column>
       <el-table-column v-if="query.p_id>0" prop="tc_price"  label="开店提成"></el-table-column>
       <el-table-column prop="sort" label="排序"></el-table-column>

       <el-table-column label="操作">
        <template slot-scope="scope">
              <el-button size="small" @click="showEdit(scope.row)">编辑</el-button>
          <el-button size="small" @click="del(scope.row)">删除</el-button>
          <el-button type="error" size="small" @click="view(scope.row)" v-if="query.p_id==0">二级分类</el-button>
            <!-- <el-button type="error" size="small" @click="showTc(scope.row)" v-if="query.p_id>0">设置开店提成</el-button> -->
        </template>
      </el-table-column>
     
    </el-table>
    

    <el-dialog title="编辑" :visible.sync="editModal" width="40%" :close-on-click-modal='false'>
        <el-form :model="item">
          <el-form-item label="名称">
            <el-input v-model="item.name" autocomplete="off"></el-input>
          </el-form-item >
             <el-form-item v-if="query.p_id>0" label="费率(%)">
            <el-input v-model="item.rate" autocomplete="off"></el-input>
          </el-form-item>
         <el-form-item v-if="query.p_id>0" label="开店提成">
            <el-input v-model="item.tc_price" autocomplete="off"></el-input>
          </el-form-item>
           <el-form-item label="排序（数字越大越靠前）">
            <el-input v-model="item.sort" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editModal = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </div>
      </el-dialog>


        <el-dialog title="编辑" :visible.sync="tcModal" width="40%" :close-on-click-modal='false'>
        <el-form :model="item">
           <el-form-item label="门店面积（*）">
          <el-select v-model="tc.area_id" placeholder="请选择" clearable>
            <el-option
              v-for="item in area"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
           <el-form-item label="提成">
            <el-input v-model="tc.price" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="tcModal = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </div>
      </el-dialog>
  
  </div>
</template>

<script>
import mixin from "../../js/mixin";

export default {
  name: "cate",
  mixins: [mixin],
  data() {
    return {
      is_page: false,
      tcModal:false,
      api_url: "shop/cate",
      query: {
        p_id: 0,
      },
      tc:{},
       area:[
        {id:1,name:'10-20'},
        {id:2,name:'20-30'},
        {id:3,name:'30-40'},
        ],
    };
  },
  components: {},
  mounted() {},
  created() {
    this.title = this.$route.meta.title;
    this.init();
  },
  methods: {
    init() {
      console.log("fuck");
      this.getData();
    },
    reset() {
      this.query.p_id = 0;
      this.getData();
    },
    view(e) {
      this.query.p_id = e.id;
      this.getData();
    },

    showTc(e){
      console.log(e)
      this.tcModal = true
    },

    changeSwitch(e){
      this.item = e 
      this.edit()
    },
    showEdit(e) {
      if (e) {
        this.item = e;
      } else {
        this.item = {
          p_id: this.query.p_id,
        };
      }
      this.editModal = true;
    },
  },
};
</script>

<style scoped>
</style>
